/**
 *
 * @param {	类型 1-企业认证（第1次） 2-交易 3-浏览活动集合页15S 4-浏览会员店铺15S 5-浏览领券中心15S} param0
 * @returns
 */
import { mapState } from "vuex";
import marketService from "@/api/market";

export default function ({ pageType }) {
  return {
    data() {
      return {
        activityTimer: null
      };
    },
    computed: {
      ...mapState(["giftActivitySwitch"])
    },
    onShow() {
      if ([3, 5].includes(pageType)) {
        this.lotteryTaskRecordCreated();
      }
    },
    methods: {
      lotteryTaskRecordCreated() {
        if (!this.giftActivitySwitch.midAutumnGift) return;
        console.log("activityMixin");
        this.activityTimer = setTimeout(() => {
          console.log("执行");
          marketService.lotteryTaskRecordCreated({ type: pageType });
        }, 15 * 1000);
      }
    },
    beforeDestroy() {
      console.log("停止定时器 beforeDestroy");
      clearTimeout(this.activityTimer);
      this.activityTimer = null;
    },
    onHide() {
      console.log("停止定时器");
      clearTimeout(this.activityTimer);
      this.activityTimer = null;
    }
  };
}
